﻿using LdtDataEngin.ModuleDetail.BaseModule;
using LdtDataEngin.ModuleDetail.CaseCauseElementExtr;
using LdtJudge.DataEngine.Common;
using LdtJudge.DataEngine.DataBaseStores;
using LdtJudge.DataEngine.Model.DataModel.SysCommon;
using LdtJudge.DataEngine.Model.XMLConfigModel.DataStores;
using LdtJudge.DataEngine.Model.XMLConfigModel.ElmentModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Xml;

namespace LdtDataEngin.ModuleDetail.AnalysisModule.ReasonElementExtract
{
    /// <summary>
    /// 理由要素分析
    /// </summary>
    public class ReasonElementExtractDetail:AssermBase
    {
        // 上下文
        private DataContext _dataContext;

        public ReasonElementExtractDetail(DataContext dataContextIn,string moudleName)
        {
            _dataContext = dataContext = dataContextIn;
            base.MoudleName = moudleName;
        }

        /// <summary>
        /// 开始提取
        /// </summary>
        /// <param name="Name">模块名称</param>
        public void Extrat()
        {
            JudgeSuggestHandle judgeSuggest = new JudgeSuggestHandle()
            {
                _dataContext = this._dataContext,
                //interActives = _dataContext.InteractiveShow
            };

            Dictionary<LdtJudge.DataEngine.Model.Personnel.PersonElementEntity, string> grouptextdic = judgeSuggest.GetGroupParseText(_dataContext.DataLayerAns.Fayanrenduanluoxinxis);
            if (_dataContext.DataLayerAns.CaseCausesList.Count > 0)
            {
                foreach (CaseCauseModel casecause in _dataContext.DataLayerAns.CaseCausesList)
                {
                    if (dataContext.DataLayerAns.SourceCode.ToLower()== "mssuitbook" )
                    {
                        
                        grouptextdic = grouptextdic.Where(a => a.Key.ParagraphCode.ToLower() == "ms_im_litigation request").ToDictionary(a => a.Key, b => b.Value);
                    }
                    if (grouptextdic != null && grouptextdic.Count>0)
                    {
                        XmlDocument xmlresult = judgeSuggest.GetCauseJudgeXml(casecause.CC_ID, grouptextdic, _dataContext.DataLayerAns.SourceCode);
                        if (_dataContext.DataLayerAns.ElementAnalysisResults == null)
                            _dataContext.DataLayerAns.ElementAnalysisResults = new Dictionary<string, XmlDocument>();
                        XmlUtilCommon xmlUtilCommon = new XmlUtilCommon() { dataContext = _dataContext };
                        DataSoursModel dataSoursModel = xmlUtilCommon.GetXMLByDataModel(xmlresult);
                        if (_dataContext.DataLayerAns.ReasonDataModel == null)
                            _dataContext.DataLayerAns.ReasonDataModel = new List<DataModel>();
                        _dataContext.DataLayerAns.ReasonDataModel.AddRange(dataSoursModel.dataModelList);
                    }
                   

                }
            }
        }
    }
}
